<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>充值套餐列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="{{URL::asset('layui/css/layui.css')}}"  media="all">
</head>
<body>
<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-group">
        <button type="button" class="layui-btn layui-btn-primary layui-btn-sm" lay-event="add"><i class="layui-icon layui-icon-add-1"></i>新增</button>
    </div>
</script>

<table class="layui-hide" id="test" lay-filter="test"></table>

<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>


<script src="{{URL::asset('layui/layui.js')}}" charset="utf-8"></script>
<script src="{{URL::asset('js/jquery-3.1.1.min.js')}}"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->

<script>
    layui.use('table', function(){
        var table = layui.table;

        table.render({
            elem: '#test'
            ,url:'/admin/recharge/api/list'
            ,toolbar: '#toolbarDemo'
            ,title: '充值套餐列表'
            ,cols: [[
                {type: 'checkbox', fixed: 'left'}
                ,{field:'id', title:'ID', width:80, fixed: 'left', unresize: true, sort: true}
                ,{field:'money', title:'价格'}
                ,{field:'score', title:'积分'}
                ,{field:'created_at', title:'创建时间',width:200}
                ,{fixed: 'right', title:'操作', toolbar: '#barDemo', width:150}
            ]]
            ,page: true
        });

        //头工具栏事件
        table.on('toolbar(test)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
            switch(obj.event){
                case 'add':
                    layer.open({
                        type:2,
                        title:"新增充值套餐",
                        area:["90%","50%"],
                        content:"/admin/score/recharge/add/html"
                    });
                    break;
            };
        });

        //监听行工具事件
        table.on('tool(test)', function(obj){
            var data = obj.data;
            //console.log(obj)
            if(obj.event === 'del'){
                layer.confirm('该操作将永久删除数据,是否确认?', function(index){
                    $.get('/admin/recharge/api/delete',{"id":data.id},function (d) {
                        if (d.code==200){
                            setTimeout(function () {
                                obj.del();
                            },300)
                        }else{
                            layer.msg("删除失败");
                        }
                    });
                    layer.close(index);
                });
            } else if(obj.event === 'edit'){
                layer.open({
                    type:2,
                    title:"编辑充值套餐",
                    area:["90%","50%"],
                    content:"/admin/score/recharge/edit/html?id="+data.id
                });
            }
        });
    });
</script>

</body>
</html>